package dao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import bean.Cliente;
import bean.Dependente;

public class DependenteDAO 
{
	private static DependenteDAO instance = new DependenteDAO();
	public static DependenteDAO getInstance()
	{ return instance; }
	
	public void salvarDependente(Session session, List<Dependente> listDependente)
	{
		for(Dependente d : listDependente)
		{
			session.save(d);
		}
	}
	
	@SuppressWarnings("unchecked")
	public List<Dependente> buscarDependente(Session session, Cliente cli)
	{
		List<Dependente> listDependente = new ArrayList<Dependente>();
		
		Criteria c = session.createCriteria(Dependente.class);
		c.add(Restrictions.eq("cliente",cli));
		listDependente = c.list();
		
		return listDependente;
	}
}
